"""
报表模块 - 数据模型定义
"""
from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel, Field


# ============ 设备运行报表 ============

class DeviceRunReportQuery(BaseModel):
    """设备运行报表查询参数"""
    keyword: Optional[str] = Field(None, description="关键字（设备序列号模糊匹配）")
    start_date: Optional[datetime] = Field(None, description="开始时间（设备创建时间范围）")
    end_date: Optional[datetime] = Field(None, description="结束时间（设备创建时间范围）")
    status: Optional[str] = Field(None, description="设备状态（单选）")
    manager_code: Optional[str] = Field(None, description="负责人工号")


class DeviceRunReportItem(BaseModel):
    """设备运行报表单条记录"""
    station_name: Optional[str] = Field(None, description="台区名称")
    box_serial_no: Optional[str] = Field(None, description="电箱序列号")
    rtu_serial_no: Optional[str] = Field(None, description="RTU序列号")
    rtu_status: Optional[str] = Field(None, description="RTU状态")
    meter_serial_no: Optional[str] = Field(None, description="电表序列号")
    meter_phase: Optional[str] = Field(None, description="相别")
    meter_status: Optional[str] = Field(None, description="电表状态")
    yesterday_kwh: float = Field(0.0, description="昨日用电量（kWh）")
    total_kwh: float = Field(0.0, description="累计电量（kWh）")
    manager_name: Optional[str] = Field(None, description="负责人姓名")
    address: Optional[str] = Field(None, description="地址")


class DeviceRunReportResponse(BaseModel):
    """设备运行报表响应"""
    total: int = Field(0, description="总记录数")
    items: List[DeviceRunReportItem] = Field(default_factory=list, description="报表数据")
    page: int = Field(1, description="当前页码")
    size: int = Field(20, description="每页大小")
    pages: int = Field(0, description="总页数")
    has_next: bool = Field(False, description="是否有下一页")
    has_prev: bool = Field(False, description="是否有上一页")


# ============ 告警工单报表 ============

class AlarmWorkReportQuery(BaseModel):
    """告警工单报表查询参数"""
    keyword: Optional[str] = Field(None, description="关键字（设备序列号模糊匹配）")
    start_date: Optional[datetime] = Field(None, description="开始时间（告警发生时间范围）")
    end_date: Optional[datetime] = Field(None, description="结束时间（告警发生时间范围）")
    alarm_status: Optional[str] = Field(None, description="告警状态（单选）")
    priority: Optional[str] = Field(None, description="优先级（单选）")


class AlarmWorkReportItem(BaseModel):
    """告警工单报表单条记录"""
    device_code: Optional[str] = Field(None, description="设备编码")
    alarm_type: Optional[str] = Field(None, description="告警类型（中文）")
    work_title: Optional[str] = Field(None, description="工单标题")
    alarm_status: Optional[str] = Field(None, description="告警状态（中文）")
    priority: Optional[str] = Field(None, description="优先级")
    raised_at: Optional[datetime] = Field(None, description="告警时间")
    recovered_at: Optional[datetime] = Field(None, description="恢复时间")
    work_code: Optional[str] = Field(None, description="工单编号")
    assignee_name: Optional[str] = Field(None, description="负责人姓名")
    description: Optional[str] = Field(None, description="工单描述")
    address: Optional[str] = Field(None, description="地址")


class AlarmWorkReportResponse(BaseModel):
    """告警工单报表响应"""
    total: int = Field(0, description="总记录数")
    items: List[AlarmWorkReportItem] = Field(default_factory=list, description="报表数据")
    page: int = Field(1, description="当前页码")
    size: int = Field(20, description="每页大小")
    pages: int = Field(0, description="总页数")
    has_next: bool = Field(False, description="是否有下一页")
    has_prev: bool = Field(False, description="是否有上一页")
